﻿
using System.Runtime.InteropServices;
using Microsoft.Extensions.Configuration;
using NetEnvironmentVariable;

var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();


try
{
    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
    {
        var java_path = configuration["ev:jdk:path"];
        var java_init = Convert.ToBoolean(configuration["ev:jdk:init"]);
        
        var node_path = configuration["ev:node:path"];
        var node_npm = Convert.ToBoolean(configuration["ev:node:npm"]);
        var node_npm_source = configuration["ev:node:source"];
        var node_install_vite = Convert.ToBoolean(configuration["ev:node:tools:vite"]);
        var node_install_vue = Convert.ToBoolean(configuration["ev:node:tools:vue"]);
        var node_install_react = Convert.ToBoolean(configuration["ev:node:tools:react"]);
        
        var anaconda_path = configuration["ev:anaconda:path"];
        var anaconda_init = Convert.ToBoolean(configuration["ev:anaconda:init"]);
        if (string.IsNullOrEmpty(java_path)==false)
        {
            if (java_init)
            {
                JavaEV.Set(java_path);
            }
        }

        if(string.IsNullOrEmpty(node_path) == false)
        {
            if (node_npm)
            {
                await NodeJsEV.Set(node_path);
                await NodeJsEV.InitNpm(node_npm_source);
            }

            if (node_install_vite)
            {
                await NodeJsEV.InstallVite();
            }

            if (node_install_vue)
            {
                await NodeJsEV.InstallVue3();
            }

            if (node_install_react)
            {
                await NodeJsEV.InstallReact();
            }

        }

        if (string.IsNullOrEmpty(anaconda_path) == false)
        {
            if (anaconda_init)
            {
                AnacondaEV.Set(anaconda_path);
            }
        }

    }
    else
    {
        Console.WriteLine("当前操作仅支持Windows系统！");
    }
    Console.WriteLine("输入任意键退出...");
}
catch (Exception e)
{
    Console.WriteLine(e);
}

Console.ReadLine();